from rest_framework import serializers
from .models import Product, ProductDetail, BrowsingRecord, FavoriteRecord, OrderRecord, CartRecord

class ProductDetailSerializer(serializers.ModelSerializer):
    class Meta:
        model = ProductDetail
        fields = ['detail_images', 'description', 'stock']

class ProductSerializer(serializers.ModelSerializer):
    detail = ProductDetailSerializer(read_only=True)
    class Meta:
        model = Product
        fields = ['id', 'name', 'price', 'original_price', 'cover_image', 'short_desc', 'tag', 'is_new', 'order', 'detail']

class BrowsingRecordSerializer(serializers.ModelSerializer):
    class Meta:
        model = BrowsingRecord
        fields = ['id', 'user', 'product', 'quantity', 'timestamp']

class FavoriteRecordSerializer(serializers.ModelSerializer):
    class Meta:
        model = FavoriteRecord
        fields = ['id', 'user', 'product', 'is_favorited', 'timestamp']

class OrderRecordSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderRecord
        fields = ['id', 'user', 'product', 'quantity', 'timestamp']

class CartRecordSerializer(serializers.ModelSerializer):
    product = ProductSerializer(read_only=True)
    class Meta:
        model = CartRecord
        fields = ['id', 'user', 'product', 'quantity', 'checked_out', 'timestamp']

